/**
 * Created by ian0214 on 2017/7/18.
 */
// options = {
//      containerId: 编辑器id
// }
const TEXT_NODE = 3;
const ELEMENT_NODE = 1;
function Editor(options) {
    var container = $("#"+options.containerId);
    
    this.getPureText = function() {
        var text = '';
        getText(container);

        function getText(parent) {
            parent.contents().each(function () {
                // console.log("this->"+this.tagName+" | "+this.nodeName+" | "+this.nodeType);
                if(this.nodeType === TEXT_NODE ){
                    var tmpText = this.textContent || this.innerText;
                    text += tmpText;
                }else if(this.nodeType === ELEMENT_NODE){
                    if(this.nodeName === 'BR'){
                        // text += "\n";
                    }else{
                        getText($(this));
                        text += "\n";
                    }
                }
            });
        }
        return text;
    }
}